document.addEventListener('DOMContentLoaded', restore_options);

//below needs optimization when populating options page gets slow
// Restores select box state to saved value from localStorage.
function restore_options() {
  var favorite = localStorage["events"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("events");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
    favorite = localStorage["redeem"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("redeem");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
      favorite = localStorage["home"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("home");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
      favorite = localStorage["games"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("games");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
      favorite = localStorage["download"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("download");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
      favorite = localStorage["competitive"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("competitive");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
     favorite = localStorage["clanPoints"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("clanPoints");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
   var  favorite2 = localStorage["clanDate"];
  if (!favorite2) {
    return;
  }
  var select2 = document.getElementById("clanDate");
  for (var i = 0; i < select2.children.length; i++) {
    var child2 = select2.children[i];
    if (child2.value == favorite2) {
      child2.selected = "true";
      break;
    }
  }
  
  favorite = localStorage["clanPagination"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("clanPagination");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
          favorite = localStorage["community"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("community");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
          favorite = localStorage["calendar"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("calendar");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
   favorite = localStorage["forumPagination"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("forumPagination");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
     favorite = localStorage["addMembers"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("addMembers");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
     favorite = localStorage["defaultFont"];
  if (!favorite) {
    return;
  }
  var select = document.getElementById("defaultFont");
  for (var i = 0; i < select.children.length; i++) {
    var child = select.children[i];
    if (child.value == favorite) {
      child.selected = "true";
      break;
    }
  }
  
  favorite = localStorage["imageSize"];
  var textbox = document.getElementById("imageSize");
  textbox.value = favorite;
}